/**
 * FileBackupBO.java
 * Created on April 6, 2007, 12:49 PM
 *
 *
 */

package edu.byu.isys413.jjenkins.data;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.fileupload.FileItem;
/**
 * This class contains the information about a file stored in backup.
 *
 * @author      Jeff Jenkins
 * @version     1.0
 */
public class FileBackupBO extends BusinessObject{
    
    /** Creates a new instance of FileBackupBO */
    public FileBackupBO() {
    }
    
    private String id;
    private String fileName;
    private String member;
    private String extension;
    private long sizeOfFile;
    private FileItem fileInfo;
    private InputStream input;
    private String icon;
    
    
    /**
     * This method accepts a FileItem as a parameter and sets all of the other
     * attributes that are associated with that FileItem. It is a shortcut to
     * calling all of the attributes seperately.
     * @param fileInfo
     */
    public void setFileAttributes(FileItem fileInfo) throws DataException{
        this.fileInfo = fileInfo;  
        fileName = fileInfo.getName();
        extension = fileInfo.getContentType();
        sizeOfFile = fileInfo.getSize();
        try {
            input = fileInfo.getInputStream();
        } catch (IOException ex) {
            throw new DataException("Can't get input stream");
        }
        this.setDirty(true);
        
    }
    
    /**
     * gets the id
     * @return id
     */
    public String getId() {
        return id;
    }
    
    /**
     * sets the id
     * @param id
     */
    public void setId(String id) {
        this.id = id;
        this.setDirty(true);
    }
    
    /**
     * gets the file name
     * @return file name
     */
    public String getFileName() {
        return fileName;
    }
    
    /**
     * sets the file name
     * @param fileName
     */
    public void setFileName(String fileName) {
        this.fileName = fileName;
        this.setDirty(true);
    }
    
    /**
     * gets the member
     * @return customer
     */
    public MemberBO getMember() {
        MemberBO membership = null;
        
        try {
            membership =  MembershipDAO.getInstance().read(member);
        } catch (DataException ex) {
            ex.printStackTrace();
        }
        
        return membership;
    }
    
    /**
     * gets the customer id
     * @return String
     */
    public String getMemberID(){
        return member;
    }
    
    /**
     * sets the member
     * @param memId
     */
    public void setMember(MemberBO member) {
        this.member = member.getId();
        this.setDirty(true);
    }
    
    /**
     * sets the member
     * @param memId
     */
    public void setMemberID(String member) {
        this.member = member;
        this.setDirty(true);
    }
    /**
     * gets the extension
     * @return extension
     */
    public String getExtension() {
        return extension;
    }
    
    /**
     * sets the extension
     * @param extension
     */
    public void setExtension(String extension) {
        this.extension = extension;
        this.setDirty(true);
    }
    
    
    /**
     * gets teh size of the file
     * @return size
     */
    public long getSizeOfFile() {
        return sizeOfFile;
    }
    
    /**
     * sets the size of the file
     * @param sizeOfFile
     */
    public void setSizeOfFile(long sizeOfFile) {
        this.sizeOfFile = sizeOfFile;
        this.setDirty(true);
    }
    
    /**
     * get the file
     * @return fileitem
     */
    public FileItem getFileInfo() {
        return fileInfo;
    }
    
    /**
     * set the file
     * @param fileInfo
     */
    public void setFileInfo(FileItem fileInfo) {
        this.fileInfo = fileInfo;
        this.setDirty(true);
    }
    
    /**
     * gets the InputStream
     * @return INputStream
     */
    public InputStream getInput() {
        return input;
    }
    /**
     * sets the InputStream
     * @param InputStream
     */
    public void setInput(InputStream input) {
        this.input = input;
        this.setDirty(true);
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }
    
    
    
    
}
